export function getList(type = 1, resultData, list, type_id) {
    let _list = [];
    let id;
    for (let i = 0; i < list.length; ++i) {
        let temp = resultData.find((item) => {
            return (
                item.input_id == list[i].id &&
                item.type_id == list[i].type_id
            );
        });
        if (temp) {
            id = temp.id;
        } else {
            id = "";
        }
        if (type == 1) {
            _list.push({
                template_id: list[i].pid,
                option_id: list[i].val.id,
                user_input: list[i].val || "",
                type_id: type_id,
                input_id: list[i].id,
                id,
            });
        } else {
            _list.push({
                template_id: list[i].pid,
                option_id: list[i].opition_type == 2 ? "" : list[i].val,
                user_input: list[i].opition_type == 2 ? list[i].val : "",
                type_id: type_id,
                input_id: list[i].id,
                id,
            });
        }
    }
    return _list;
}


export function setList(_this, list, item, type = 1) {

    list.forEach((e) => {
        if (item.input_id == e.id) {
            if (e.opition_type == 1) {
                e.templateOptions.forEach((ele) => {
                    if (ele.id == item.option_id) {
                        if (type == 1) {
                 
                            _this.$set(e, "val", { name: ele.name, id: ele.id });
                        } else {
                            _this.$set(e, "val", ele.id);
                        }
                    }
                });
            } else { 
                
            _this.$set(e, "val", item.user_input);

        }
    }
    });
}

// 获取成员列表信息
export function getRememberList(resultData, list, type_id) {
    let _list = [];
    let id;
    let template_id = list[0].list[0].pid;
    let option_id = "";
    let user_input = [];
    let input_id = "";


    let temp = resultData.filter((item) => {

        return (
            item.template_id == list[0].list[0].pid &&
            item.type_id == type_id)

    });

    if (temp.length > 0) {
        id = temp[0].id;
    } else {
        id = "";
    }

    for (let i = 0; i < list.length; ++i) {
        let temp = []
        list[i].list.forEach(item => {
            temp.push(item.val);
        })
        user_input.push(temp);
    }

    _list = [{
        template_id: template_id,
        user_input: JSON.stringify(user_input),
        option_id: option_id,
        input_id: input_id,
        type_id: type_id,
        id: id
    }]

    return _list;
}





// 初始化数据
export function init(_this, arr) {
    arr.forEach((item) => {
        if (item.opition_type == 1) {
            if (item.id == 199 || item.id == 200) {
                item.opition_type = 3;
                _this.$set(item, "val", "");

            } else {
                _this.$set(item, "val", "");
            }
        } else {
            _this.$set(item, "val", "");
        }
        _this.$set(item, "visible", false);
    });
}



